package Controller.Eboard;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;
import org.springframework.web.servlet.mvc.Controller;

import Dao.eboardDao;
import Bean.eboardBean;

public class EboardupdateContoller extends AbstractCommandController{
	private eboardDao dao;
	public void setDao(eboardDao dao){
		this.dao = dao;
	}


	@Override
	protected ModelAndView handle(HttpServletRequest req,
			HttpServletResponse res, Object obj, BindException arg3)
			throws Exception {
		res.setCharacterEncoding("UTF-8");
		String contents = req.getParameter("eb_context");
		contents = contents.replace("\r\n", "<br>");
		
		eboardBean bean = (eboardBean)obj;
		bean.setEb_context(contents);
		
		System.out.println("빈으로 받은");
		System.out.println(bean.getEb_no());
		System.out.println(bean.getEb_count());
		System.out.println(bean.getEb_title());
		System.out.println(bean.getEb_context());
		
		Integer eb_no = bean.getEb_no();
		
		System.out.println("req로 받은");
		System.out.println(req.getParameter("eb_no"));
		System.out.println(req.getParameter("eb_conunt"));
		System.out.println(req.getParameter("eb_title"));
		System.out.println(req.getParameter("eb_context"));
		System.out.println("업데이트 수정 완료");

		dao.eboardupdate(bean);
		
		System.out.println("다오 실행 완료");
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("redirect:/eboarddetail.eboard?eb_no="+eb_no);
		return mav;
		
	}
}
